package com.breaktian.assemble.schedule;

import java.util.TimerTask;
import java.util.UUID;

/**
 * Created by breaktian on 2016/12/23.
 */

public abstract class CommonTask extends TimerTask {
    private int id;
    private boolean isRunning;

    public CommonTask(int id){
        this.id = id;
    }

    public CommonTask(){
        this.id = UUID.randomUUID().hashCode();
    }

    public int getId(){
        return this.id;
    }

    public boolean isRunning(){
        return isRunning;
    }


    @Override
    public void run() {
        isRunning = true;
        doTask();
    }

    public void stop(){
        cancel();
        isRunning = false;
    }

    protected abstract void doTask();
}